package com.elvin.platform.tcp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;


public class TcpServer {

    public static void main(String[] args) throws IOException {
        String getString;
        String sendString;
        ServerSocket socket = new ServerSocket(6789);
        //ServerSocket 为服务器监听的类
            //收到accept请求,返回socket实例
            Socket connection = socket.accept();
            System.out.println("connect successfully");
            //获得输入的内容,即客户端程序发送过来的消息
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            //发送回去的内容
           // DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
            while((getString=reader.readLine())!=null){
                System.out.println("客户端接收到的消息："+getString);
            }
            System.out.println("进入！");
           // sendString = getString.toUpperCase() + "\n";
            //将内容写入到想要返回给客户端的流中
           // System.out.println("接收到的："+sendString);
            //outputStream.writeBytes(sendString);
             //关闭流
            reader.close();
            connection.close();
    }}
